from application import init_app, db, set_env, make_celery
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
import pysnooper
# @pysnooper.snoop(depth=10)

app = init_app()
cel = make_celery(app)
# 使用终端管理工具
manager = Manager(app)

# 使用数据迁移工具
Migrate(app, db)

# 添加数据库迁移命令到终端脚本工具中
manager.add_command('db', MigrateCommand)

@manager.option('-e', '--env', dest='env', default='dev')
def env(env):
    """
    配置运行环境
    """
    if env == "dev" or env == "pro":
        try:
            set_env(env)
            return "切换环境成功"
        except:
            return "切换环境失败"
    else:
        return "切换环境失败，当前环境不存在"


# 导入模型[为了进行数据迁移]
# from application.apps.case_library.models import Case
# from application.apps.ci.models import JobTask

@app.route('/')
def index():
    return 'index'


if __name__ == '__main__':
    manager.run()
